/* 
Set directory 
*/

    global root ENTER DIRECTORY
                                
	global yls 		"$root\Analysis\Dta\Young Lives"
	
	global output 	ENTER DIRECTORY


*YLS*
use "$yls\small_temp_time.dta", clear	

label var n_raw_math "Math Score (in SD)"
label var n_raw_ppvt "PPVT Score (in SD)"

label var lncrops "Crops"
label var lnanimals "Animals"
label var lnvege_fruit "Veg-Fruits"
label var lnowncrops "Own Crops"
label var lnownanimals "Own Animals"
label var lnownvege_fruit "Own Veg-Fruits"

label var absent "School Absence"
label var sick_ab "Reason: Illness"



label var dbin "Day-of-Test $>$23C"
label var bin1 "Day-of-Test $<$23C"
label var bin2 "Day-of-Test 23-25C"
label var bin3 "Day-of-Test 25-27C"
label var bin4 "Day-of-Test $>$27C"

label var w_math_dur "Duration Math Test"
label var w_ppvt_dur "Duration PPVT Test"

label var math_st_hr "Math Start Time"
label var ppvt_st_hr "PPVT Start Time"

label var dlbin "Days Between Two Tests $>$23C"
label var lbin1 "Days Between Two Tests $<$23C"
label var lbin2 "Days Between Two Tests 23-25C"
label var lbin3 "Days Between Two Tests 25-27C"
label var lbin4 "Days Between Two Tests $>$27C"

label var ll1ybin1 "PY Days $<$23C"
label var ll1ybin2 "PY Days 23-25C"
label var ll1ybin3 "PY Days 25-27C"
label var ll1ybin4 "PY Days $>$27C"

label var ybin1 "CY Days $<$23C"
label var ybin2 "CY Days 23-25C"
label var ybin3 "CY Days 25-27C"
label var ybin4 "CY Days $>$27C"

bys childid: gen idays_new = idate5 - idate3
replace idays = idays_new if idays == . & idate2 != .

label var Weightedavg_temp "Daily Average Temperature (C)"


*Table 3
local tablename "T3"
local table=1
local col=1
estimates clear

xtreg n_raw_math dlbin dbin idays lavg_rain lavg_rainsq lavg_raincu rain1 rain3  i.round i.month  i.dayofweek  if bal_math == 3 & bal_ppvt == 3, fe cluster(distid_week) nonest
estimates store cT`table'C`col++'

xtreg n_raw_math lbin2 lbin3 lbin4 bin2 bin3 bin4  idays lavg_rain lavg_rainsq lavg_raincu  rain1 rain3  i.round i.month  i.dayofweek if bal_math == 3 & bal_ppvt == 3, fe cluster(distid_week) nonest
estimates store cT`table'C`col++'

xtreg n_raw_ppvt dlbin dbin idays lavg_rain lavg_rainsq lavg_raincu rain1 rain3 i.round i.month i.cohort i.dayofweek if bal_ppvt == 3 & bal_math == 3 & mismatch_dates == ., fe cluster(distid_week) nonest
estimates store cT`table'C`col++'

xtreg n_raw_ppvt lbin2 lbin3 lbin4 bin2 bin3 bin4 idays lavg_rain lavg_rainsq lavg_raincu rain1 rain3 i.round i.month i.cohort i.dayofweek if bal_ppvt == 3 & bal_math == 3 & mismatch_dates == ., fe cluster(distid_week) nonest
estimates store cT`table'C`col++'

esttab cT`table'C* using "$output/`tablename'.tex", replace f ///
               label booktabs b(3) p(3) eqlabels(none) alignment(S) collabels("\multicolumn{1}{c}{$\beta$ / SE}") ///
               keep (dlbin lbin2 lbin3 lbin4 dbin bin2 bin3 bin4  , relax) ///
			   star(* 0.10 ** 0.05 *** 0.01) ///
               cells("b(fmt(3)star)" "se(fmt(3)par)") ///
			   stats(N r2, fmt(0 3) layout("\multicolumn{1}{c}{@}") ///
			   labels(`"Observations"' `"\(R^{2}\)"'))
